package com.itmate.chenshiguang.contreolle;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itmate.chenshiguang.dao.AccountDao;
import com.itmate.chenshiguang.entity.account;
import com.itmate.chenshiguang.service.AccountUserService;

/**
 * Servlet implementation class test
 */
@WebServlet("/text")
public class text extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public text() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
//		String year=request.getParameter("year");
//		String month=request.getParameter("month");
		AccountUserService a=new AccountUserService();
		List<String> dataIn=new ArrayList<>();
		List<String> dataOut=new ArrayList<>();
		List<String> x=new ArrayList<>();
		List<account> ac=new ArrayList<>();
		Map<String,Integer> map=new HashMap<>();
		ac=a.selectAllUser();
		for(account acc:ac){
			String temp=acc.getStatue();
			if(temp.equals("收入")){
				dataIn.add(String.valueOf(acc.getMoney()));
				x.add(acc.getDate());
			}
			else if(temp.equals("支出")){
				dataOut.add(String.valueOf(acc.getMoney()));
			}
		}
		System.out.println(dataOut);
		System.out.println(dataIn);
		System.out.println(x);

		request.getRequestDispatcher("/WEB-INF/jsp/csg/text.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
//	public static int getDay(Date data){
//		Calendar calendar=Calendar.getInstance();
//		calendar.setTime(data);
//		return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
//	}
//	public static void main(String[] args){
//		Date a=new Date();
//		System.out.println(getDay(a));
//	}

}

